package com.sodaopen.crm.sys.entity;

import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * <p>
 * 
 * </p>
 *
 * @author SodaJava
 * @since 2020-07-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("sys_user")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "用户名不能为空")
    @Size(min = 3, max = 16, message = "用户名长度在3到16位")
    @Pattern(regexp = "[a-zA-Z]\\w{2,15}", message = "用户名存在不合法字符")
    private String username;

    @JsonIgnore
    private String password;

    private String name;

    private String email;

    private String mobile;

    @JsonIgnore
    private Integer status;
    
    //为方便前端调用提供的虚拟字段
    public boolean isAvailable() {
    	return getStatus() == 0;
    }
    
    public void setAvailable(boolean available) {
    	setStatus(available ? 0 : 1);
    }


}
